import { createRouter, createWebHashHistory } from 'vue-router'

const router = createRouter({
    history: createWebHashHistory(),
    routes: [
        {
            path: '/',
            component: () => import('../layout/HomeLayout.vue'),
            meta: {
                title: ''
            },
            redirect: '/login',
            children: [
                {
                    path: 'login',
                    component: () => import('../pages/login/index.vue'),
                    meta: {
                        title: '登录'
                    },
                },
            ]
        },
        {
            path: '/liveSet',
            component: () => import('../pages/liveSet/index.vue'),
            meta: {
                title: '开播设置'
            },
        },
        {
            path: '/screenShare',
            component: () => import('../pages/screenShare/index.vue'),
            meta: {
                title: '屏幕共享'
            },
        },
    ]
});


router.beforeEach((to, from, next) => {
    document.title = to.meta.title || 'caihu'
    if(to.path == '/login'){
        next()
    }else{
        if(window.localStorage.getItem('teacher_user')){
            next()
        }else{
            next('/login')
        }
    }
})

export default router